package com.vercon.common.utils;

import android.util.Log;

import androidx.fragment.app.FragmentActivity;

import java.lang.ref.WeakReference;

/**
 * Created by csh on 2020/12/14
 */
public class TopActivityManager {
    private static final String TAG = "TopActivityManager";
    public static TopActivityManager instance = new TopActivityManager();
    private WeakReference<FragmentActivity> currentActivityWeakRef;

    public TopActivityManager() {

    }

    public static TopActivityManager getInstance() {
        return instance;
    }

    public FragmentActivity getCurrentActivity() {
        FragmentActivity currentActivity = null;
        if (currentActivityWeakRef != null) {
            currentActivity = currentActivityWeakRef.get();
        }
        return currentActivity;
    }

    public void setCurrentActivity(FragmentActivity activity) {
        currentActivityWeakRef = new WeakReference(activity);
        Log.d(TAG, currentActivityWeakRef.get().getClass().getSimpleName());
    }

} 